import 'package:enterprise_v6_app/app/components/custom_modele/custom_dropdown_selection.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_search_enter.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_icon_title_view.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/entities/application/smart_warehouse/warehouse_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/smart_warehouse/warehouse_management/warehouse_management_controller.dart';

/// 仓库管理页面
class WarehouseManagementPage extends StatelessWidget {
  WarehouseManagementPage({super.key});

  final controller = Get.put(WarehouseManagementController());

  //获取条件搜索项
  Widget _getSearchConditionWidget() {
    return Column(
      children: [
        CustomSearchEnter(
          hintText: '搜索仓库名称',
          text: controller.search,
          onCallBack: (value) {
            controller.search = value;
            controller.refreshPage();
          },
        ),
        AppGaps.vGap8,
        CustomDropdownSelection(
          text: controller.currentSituation.getShowName(),
          hintText: '选择现存情况',
          onCallBack: controller.showCurrentSituationSelection,
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Container(
            padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 14.w),
            alignment: Alignment.topCenter,
            color: const Color(0xffF5F5F6),
            child: Column(children: [
              _getSearchConditionWidget(),
              AppGaps.vGap14,
              Expanded(
                child: CustomEasyRefreshList<WarehouseEntity>(
                  key: controller.globalKey,
                  dataLoad: (pageIndex, pageSize, {String? search}) async {
                    return controller.getWarehouseListData(pageIndex, pageSize);
                  },
                  itemBuilder: (WarehouseEntity item, int index) {
                    return CustomTitleChartPage(
                      titleView: Stack(
                        alignment: Alignment.centerRight,
                        children: [
                          CustomIconTitleView(
                            title: '${item.warehouseName}（${item.warehouseArea}㎡）',
                          ),
                          Visibility(
                              visible: item.excess,
                              child: Container(
                                margin: EdgeInsets.only(right: 16.w),
                                child: SvgPicture.asset(
                                  AppImages.icon_excess,
                                  width: 43.w,
                                  height: 20.w,
                                  // colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
                                ),
                              )),
                        ],
                      ),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              Text(
                                '储存量：',
                                style: TextStyle(
                                  fontSize: 13.sp,
                                  height: 1.2,
                                  fontWeight: FontWeight.w400,
                                  color: const Color(0xffA5A6B5),
                                ),
                              ),
                              Expanded(
                                  child: Text(
                                '${item.warehouseStore}kg',
                                textAlign: TextAlign.right,
                                style: TextStyle(
                                  fontSize: 16.sp,
                                  height: 1.2,
                                  fontWeight: FontWeight.w400,
                                  color: const Color(0xff5C6DFF),
                                ),
                              ))
                            ],
                          ),
                          AppGaps.vGap10,
                          Row(
                            children: [
                              Text(
                                '安全负责人：',
                                style: TextStyle(
                                  fontSize: 13.sp,
                                  height: 1.2,
                                  fontWeight: FontWeight.w400,
                                  color: const Color(0xffA5A6B5),
                                ),
                              ),
                              Expanded(
                                  child: Text(
                                '${item.sadetyPersonName}',
                                textAlign: TextAlign.right,
                                style: TextStyle(
                                  fontSize: 12.sp,
                                  height: 1.2,
                                  fontWeight: FontWeight.w400,
                                  color: const Color(0xff495061),
                                ),
                              ))
                            ],
                          ),
                        ],
                      ),
                    ).clickOnce(() {
                      controller.toDetailsPage(item.id!);
                    });
                  },
                ),
              ),
            ]),
          );
        });
  }
}
